package com.luke.source.pattern;

import io.netty.util.concurrent.EventExecutor;

/**
 * @see io.netty.util.concurrent.DefaultEventExecutorChooserFactory#newChooser(EventExecutor[])
 *
 * 策略模式：第一步：算法家族  第二步：算法选择规则
 *
 */
public class Strategy {

    //==============================第一步：算法家族=============================================

    public interface Cache{
        boolean add(String key,Object object);
    }

    public class CacheMemoryImpl implements Cache {
        @Override
        public boolean add(String key, Object object) {
            //保存到map中
            return false;
        }
    }

    public class CacheRedisImpl implements Cache {
        @Override
        public boolean add(String key, Object object) {
            //存储到redis
            return false;
        }
    }

    //=============================第二步：算法选择规则=========================================

    private Cache cacheMemory = new CacheMemoryImpl();
    private Cache cacheRedis = new CacheRedisImpl();

    public Cache chooseCache(String key){
        if(key.length() <= 10){
            return cacheMemory;
        }
        return cacheRedis;
    }

}
